Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Test failing...] DDC-1048 reported by cordoval #647

Closed
wants to merge 1 commit into from

Conversation

cordoval
Copy link
Contributor

@doctrinebot
Copy link

Hello,

thank you for creating this pull request. I have automatically opened an issue
on our Jira Bug Tracker for you. See the issue link:

http://www.doctrine-project.org/jira/browse/DDC-2397

We use Jira to track the state of pull requests and the versions they got
included in.

@Padam87
Copy link
Contributor

Padam87 commented Apr 10, 2013

馃憤

Ran into this issue with one of my bundles, fortunately I only needed it for the query builder, and made it work without creating an expression.

I believe the cause of the problem is this:
https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Query/Expr/Comparison.php#L98

@Majkl578
Copy link
Contributor

This is a DQL issue (or DQL builder issue, to be specific), not a mapping or MySQL-specific issue. I think @Padam87 is correct, $rightExpr requires some inspection and I'm afraid that the problem affects also other Expr classes, not only Comparison.
The question is whether it's a bug or not, since DQL is a string and TRUE/FALSE is also a string in DQL.
Anyway, there should be two simple workarounds for this (in fact, second one is not a workaround, but a regular usage):
a) Use string representation:

$qb->expr()->eq('x.booleanField', 'FALSE');

or use parameter:

$qb->expr()->eq('x.booleanField', ':foo');
$qb->setParameter('foo', FALSE);

@pylebecq
Copy link

@Majkl578 The second one does not work for me, it works only if false is a string and not a boolean :

$qb->expr()->eq('x.booleanField', ':foo');
$qb->setParameter('foo', 'false');

@Majkl578
Copy link
Contributor

This should work then:

$qb->setParameter('foo', FALSE, \Doctrine\DBAL\Types\Type::BOOLEAN);


$false = $qb
->where($qb->expr()->andX(
$qb->expr()->eq('x.booleanField', false),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cordoval This is using string concatenation. It is expected to work this way. You should use parameters instead

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is, DQL supports booleans without parameters so one would expect this to work. This behavior is at least strange and unexpected.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Majkl578 But it supports it by using a string, not a boolean.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but that doesn't mean DQL builder can't use some extra logic for converting input to string representation (which would make sense here). Also, looking at Comparison::__construct, it says @param mixed $rightExpr, not @param string $rightExpr.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, because it could be another Expr

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The query builder is a string builder and has nothing to do with casting constant values to their corresponding DQL representations. here, binding a string would mean using '"false"' and binding a boolean would require to use 'false', and not just the boolean false. these are all different

@Ocramius
Copy link
Member

Invalid

@Ocramius Ocramius closed this Apr 12, 2013
@cordoval
Copy link
Contributor Author

i tried 馃懚

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants